import java.io.*;
import java.util.Scanner;

public class Demo2 {
    public static void main(String[] args) throws IOException {
        System.out.println("请输入你要复制的文件路径：");
        Scanner scan = new Scanner(System.in);
        String str = scan.next();
        File file = new File(str);

        if(!file.isFile()) {
            System.out.println("你输入的不是文件或者该文件不存在...");
            return;
        }

        System.out.println("请输入你要复制的路径：");
        String end = scan.next();
        File file2 = new File(end);
        if(!file2.getParentFile().isDirectory()) {
            System.out.println("要复制到的文件路径不存在...");
            return;
        }

        byte[] b = new byte[1024];
        try(InputStream inputStream = new FileInputStream(str);
            OutputStream outputStream = new FileOutputStream(end);
        ) {
            while(true) {
                int n = inputStream.read(b);
                if(n == -1) {
                    break;
                }
                outputStream.write(b,0, n);
            }
        }
        System.out.println("复制成功");
    }
}
